<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateAdvertTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('advert', ['comment'=>'广告表'])
            ->addColumn(Column::string('title')->setNullable()->setComment('广告名称'))
            ->addColumn(Column::text('content')->setNullable()->setComment('广告内容'))
            ->addColumn(Column::string('link', 500)->setNullable()->setComment('跳转链接'))
            ->addColumn(Column::string('photo_link')->setNullable()->setComment('图片地址'))
            ->addColumn(Column::integer('page_view')->setDefault(0)->setNullable()->setComment('浏览量'))
            ->addColumn(Column::integer('init_view')->setDefault(0)->setNullable()->setComment('初始浏览量'))
            ->addColumn(Column::integer('capacity')->setNullable()->setDefault(0)->setComment('加载量'))
            ->addColumn(Column::integer('max_capacity')->setNullable()->setDefault(0)->setComment('最大加载量'))
            ->addColumn(Column::integer('user_id')->setNullable()->setComment('创建者'))
            ->addColumn(Column::tinyInteger('place')->setNullable()->setDefault(0)->setComment('1 pc端，2 移动端'))
            ->addColumn(Column::integer('publish')->setNullable()->setDefault(0)->setComment('0 待发布，1 已发布， 2 已下架'))
            ->addColumn(Column::integer('create_time')->setComment('创建时间'))
            ->addColumn(Column::integer('update_time')->setComment('修改时间')->setNullable())
            ->addColumn(Column::integer('delete_time')->setComment('删除时间')->setNullable())
            ->create();
    }
}
